Calculate Area of a Triangle

Theory:

The area of a triangle can be calculated using the formula: Area = (base * height) / 2, where base is the length of the base of the triangle and height is the perpendicular height from the base to the opposite vertex.

Python Code:

def calculate_triangle_area(base, height):
return (base * height) / 2

# Taking input from the user for the base and height
base = float(input("Enter the length of the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
area = calculate_triangle_area(base, height)
print("Area of the triangle with base", base, "and height", height, "is:", area)

Example:

Enter the length of the base of the triangle: 5

Enter the height of the triangle: 8

Area of the triangle with base 5 and height 8 is: 20.0

Example:

Enter the length of the base of the triangle: 10

Enter the height of the triangle: 12

Area of the triangle with base 10 and height 12 is: 60.0

Code Explanation:

The function calculate_triangle_area(base, height) takes the length of the base and the height of the triangle as input and returns the area of the triangle using the formula (base * height) / 2.

The example usage section demonstrates how to take input from the user for the base and height, calculate the area of the triangle, and print the result.